﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using BLL;
using Model;
using Ysb.Components;

public partial class Admin_OtherEdit : System.Web.UI.Page
{
    DataTable dt1 = null;
    DataTable dt2 = null;
    DataTable dt3 = null;
    DataTable dt4 = null;
    public string pcount;
    public string ajax;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            string lb = Request.QueryString["no"].ToString();



            List<TnoInfo> lst = new List<TnoInfo>();

            lst = new WayBillService().GetList(lb, 4);



            if (lst.Count == 0)
            {
                showerr.Text = "你当前并未选择单据进行编辑";

            }


          using ( DataTable ndt = new WayBillService().GetBillMess("'False' as Sep, '' as Description, TrackingNo,FlightNo,AerialNo,CreateDate,Origin,Destination,Payment,Packing", "'True' as Sep,Description,SepNo as TrackingNo,FlightNo,AerialNo,CreateDate,Origin,Dest as Destination,PayType as Payment ,Packing ", lst, 1))

        {


            dt1 = new PublicSqlService().GetData("*", "Tbl_Place", "IsStart=1");
            dt2 = new PublicSqlService().GetData("*", "Tbl_Place", "IsEnd=1");
            pcount = dt2.Rows.Count.ToString();
            dt3 = new PublicSqlService().GetData("*", "Tbl_PayModel", "");
            list.DataSource = ndt;
            list.DataBind();
        }
        }
    }

    public DataTable GetDt(int no, string Tno, string seletview)
    {


        switch (no)
        {
            case 1:

                ajax += " SetPalce1('" + Tno + "','" + seletview + "');";
                return dt1;

            case 2:
                ajax += " SetPalce2('" + Tno + "','" + seletview + "');";
                return dt2;

            case 3:
                ajax += " SetPay('" + Tno + "','" + seletview + "');";
                return dt3;


        }
        return null;

    }

    public string GetTitle(int type, string tno)
    {
        switch (type)
        {
            case 1:


                return "p1" + tno;

            case 2:
                return "p2" + tno;

            case 3:
                return "p3" + tno;


        }
        return "";
    }

    public string GetHuowuName(string tno, string value)
    {
        ajax += " Sethuowu('" + tno + "','" + value + "');";
        return "p4" + tno;
    }
    protected void okbtn_Click(object sender, ImageClickEventArgs e)
    {

        toPost();

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        //拼命
        bool ok = toPost();     
        Response.Redirect("NameEdte.aspx?no=" + Request.QueryString["no"].ToString());
      
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        //加个
        bool ok = toPost();
        Response.Redirect("PriceEdit.aspx?no=" + Request.QueryString["no"].ToString());
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        //login
        bool ok = toPost();
        Response.Redirect("BillLogoPl.aspx?no=" + Request.QueryString["no"].ToString());
    }
    bool toPost()
    {
        int sum = 0;
        int sumsep = 0;
        Hashtable hs = new Hashtable();
        string e4rr = "";
        for (int i = 0; i < list.Items.Count; i++)
        {
            Label sep = (Label)list.Items[i].FindControl("IsSep");

            Label no = (Label)list.Items[i].FindControl("no_txt");




            DropDownList qyd = (DropDownList)list.Items[i].FindControl("qiyudi");
            DropDownList mdd = (DropDownList)list.Items[i].FindControl("mudidi");
            DropDownList pay = (DropDownList)list.Items[i].FindControl("zhifufangshi");
            DropDownList huowu = (DropDownList)list.Items[i].FindControl("huopwuzl");
            HtmlInputText create = (HtmlInputText)list.Items[i].FindControl("createdt");
            HtmlInputText cankao = (HtmlInputText)list.Items[i].FindControl("cankao");
            HtmlInputText hangkongdanhao = (HtmlInputText)list.Items[i].FindControl("hangkongdanhao");




            if (sep.Text.Trim() == "")
            {
                //主单
                hs.Clear();


                //分单
                hs.Add("FlightNo", cankao.Value);//参考号
                hs.Add("AerialNo", hangkongdanhao.Value);//航空单号
                hs.Add("CreateDate", new Tools().StringToTime(create.Value));
                hs.Add("Origin", qyd.SelectedItem.Text);//气韵第
                hs.Add("Destination", mdd.SelectedItem.Text);//目的地
                hs.Add("Payment", pay.SelectedValue); //支付防暑
                hs.Add("Packing", huowu.SelectedValue);//包装形式


                if (new PublicSqlService().Update(hs, "Tbl_WayBill", "TrackingNo='" + no.Text.Trim() + "'"))
                {
                    sum++;
                }


            }
            else
            {
                HtmlInputText daihao = (HtmlInputText)list.Items[i].FindControl("daihao");


                hs.Clear();
                //分单
                hs.Add("FlightNo", cankao.Value);//参考号
                hs.Add("AerialNo", hangkongdanhao.Value);//航空单号
                hs.Add("CreateDate", new Tools().StringToTime(create.Value));
                hs.Add("Origin", qyd.SelectedItem.Text);//气韵第
                hs.Add("Dest", mdd.SelectedItem.Text);//目的地
                hs.Add("PayType", pay.SelectedValue); //支付防暑
                hs.Add("Packing", huowu.SelectedValue);
                hs.Add("Description", daihao.Value.Trim());//袋号

                if (new PublicSqlService().Update(hs, "Tbl_SepBill", "SepNo='" + no.Text.Trim() + "'"))
                {
                    sumsep++;
                }

            }



        }

        /// Tools.OpenWindow(this, , Request.Url.ToString());
 
        Tools.OpenWindow(this, "编辑成功！共编辑：" + (sumsep + sum).ToString() + "条数据;");
        return true;
  
    }
}
